package collectionDemo;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author Ajie
 * @date 5/19/21
 * @function
 */
public class DequeDemo {

    public static void main(String[] args) {
        Deque<Person> deque = new ArrayDeque<>();

        for (int i = 0; i < 5; i++) {
            deque.add(new Person(String.valueOf(i)));
        }

        System.out.println(deque.contains(new Person("2")));
    }

    static class Person {
        String id;

        public Person(String id) {
            this.id = id;
        }

        @Override
        public int hashCode() {
            return id==null?-1:Integer.valueOf(id);
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null ){
                return false;
            }
            if (obj instanceof Person){
                return this.id.equals(((Person) obj).id);
            }
            return false;
        }
    }

}
